﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace thinger.ADONETTeach
{
    class Program
    {
        static void Main(string[] args)
        {
            //测试连接和关闭
            CRUDBase crudBase = new CRUDBase();
            /* crudBase.ConnectDB();
             crudBase.Insert();*/
            //crudBase.Update();
            //crudBase.Delete();
            //crudBase.GetSingleResult1();
            //crudBase.GetSingleResult2();
            //crudBase.GetReaderList1();
            //crudBase.GetReaderList2();
            //crudBase.GetDataSet1();
            //crudBase.GetDataSet2();

            //TestException();
            //ThrowException();
            //TestThrow();
            CRUDBaseForHelper baseHelper = new CRUDBaseForHelper();
            //baseHelper.Insert();
            baseHelper.GetReaderList();
            //baseHelper.Update();
            //baseHelper.GetSingleResult();
            //baseHelper.GetDataSet1();
            //baseHelper.GetDataSet2();

            //CRUDAdvance advanceHelper = new CRUDAdvance();
            //advanceHelper.Insert2();

            Console.Read();
        }
        static void TestException()
        {
            int a = 100;
            int b = 0;
            try
            {
                int c = a / b;
            }
            catch(DivideByZeroException ex)
            {
                Console.WriteLine("程序检测到B的值为0，0不能做出书我，请检查相关数据");
            }
            catch(System.Data.SqlClient.SqlException ex)
            {
                //数据库访问出现...异常
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        #region 完整的异常处理框架
        static void TestThrow()
        {
            try
            {
                ThrowException(); //因为这个地方有异常出现的可能，所以必须再次处理
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        static string ThrowException()
        {
            int a = 100;
            int b = 0;
            try
            {
                int c = a / b;
                //程序逻辑
                return "运算成功";
            }
            catch (Exception ex)
            {
                //在这个地方写入日志
                throw new Exception("相除运算出现异常！具体原因请参考:"+ex.Message);
            }
        }
        #endregion


    }
}
